﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="TripLOA.WebService.georef_test_2.Test" %>
<%@ Register Assembly="MapControl2" Namespace="MapControl2" TagPrefix="map2" %>

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head runat="server">
<title>Georef MapControl2 Test</title>
        <style type="text/css">
            #form1
            {
                height: 132px;
            }
        </style>
        <style> v\:* { behavior: url(#default#VML); }</style >
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="myScriptManager" runat="server">
            <Services>
                <asp:ServiceReference Path="~/service/georef_test_2/WSGeoRef.asmx" InlineScript="false" />
            </Services>
        </asp:ScriptManager>
        
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:Button ID="Button1" runat="server" Text="Click me" OnClick="ClickButton1" />
                <asp:Button ID="Button2" runat="server" Text="Add Waypoint" OnClientClick="testWaypoint()" />
                <asp:Button ID="Button3" runat="server" Text="add destination" OnClientClick="testAddDestination()" />
                <asp:Button ID="Button4" runat="server" Text="add start" OnClientClick="testAddStart()" />
                <asp:Button ID="Button5" runat="server" Text="Istr" OnClientClick="testGetIstructions()" />
                <asp:Button ID="Passenger" runat="server" Text="Get Passenger" 
                    onclick="Passenger_Click" />
                <map2:LOAMap ID="map2_id" runat="server" MapDiv="map_id" GoogleApiKey="ABQIAAAA6PuMZvkqJDY35l18oPnbjBRRz0caoklsKOxz4pKCS_kzV_zgVxQSDzfMTFThh6IZ-gGO2triLzhq-w"
                    Editable="false" TargetControlIDs="Button1" ZoomLevel="10"/>
                <asp:Button ID="PassengerDet" runat="server" OnClientClick="DetachPassangers()" 
                    Text="Detach Passenger" />
                <asp:Button ID="ButtonClear" runat="server" 
                    OnClientClick="clearEditableTrip()" Text="Clear Editable Trip" />
                <asp:Button ID="Button6" runat="server" onclick="changingPassenger" 
                    Text="Change Pass" />
                <asp:Button ID="Button7" runat="server" onclick="Button7_Click" Text="Test" 
                    onclientclick="SwapEditable()" />
                <div style="background-color: #FF99FF; position: relative; width: 334px; top: 3px; left: 599px; height: 29px;" 
                    align="center">
                    <asp:Button ID="inserting1" runat="server" 
                        Text="Attach Passenger" Width="120px" 
                        onclientclick="AttachingPassaenger()" />
                    <asp:TextBox ID="passRI" runat="server" Width="40px"></asp:TextBox>
                    <asp:TextBox ID="passSRI" runat="server" Width="40px"></asp:TextBox>
                    <input ID="depradio" name="pass" type="radio" value="Dep" checked /> Dep
                    <input ID="arrradio" name="pass" type="radio" value="Arr" /> Arr
                </div>
                <div align="center" 
                    style="background-color: #00FFCC; position: relative; width: 424px; top: -25px; left: 3px; height: 29px;">
                    <asp:Button ID="inserting" runat="server" onclick="InsertingRoute_Btm" 
                        Text="Insert Route" Width="106px" />
                    <asp:TextBox ID="routeIndex" runat="server" Width="40px"></asp:TextBox>
                    <asp:TextBox ID="waypointIndex" runat="server" Width="40px"></asp:TextBox>
                    <asp:TextBox ID="coord" runat="server" Width="193px"></asp:TextBox>
                </div>
                <div style="background-color: #FFFF66; position: relative; top: -53px; height: 26px; width: 159px; left: 433px;" 
                    align="center">
                    <asp:Button ID="inserting0" runat="server" onclick="RemovingRoute_Btm" 
                        Text="Remove Step" Width="106px" />
                    <asp:TextBox ID="markerStageIndex" runat="server" Width="40px"></asp:TextBox>
                </div>
                <div>
                    <asp:Label ID="latlnglabel" runat="server" Text="(x, x)" ></asp:Label>
                </div>
            </ContentTemplate>
        </asp:UpdatePanel>
        
        <div id="map_id" 
            
            style="position: absolute; top: 141px; left: 10px; width: 100%; height: 423px"></div>
       <div id="outputDiv" 
            
            style="position: absolute; top: 600px; left: 10px; width: 100%"></div>   
    </form>
    
    <script type="text/javascript">
       
        function testAddDestination()
        {
            var map = Sys.Application.findComponent("map2_id");
            var stop = new google.maps.LatLng(43.47624, 10.7289);
            map._map._editableTrip.insertStop(4, stop); 
        };
        
        function testAddStart()
        {
            var map = Sys.Application.findComponent("map2_id");
            var start = new google.maps.LatLng(43.72778, 10.80678);
            map._map._editableTrip.insertStop(0, start); 
        };
    
        function getJson()
        {
            var map = Sys.Application.findComponent("map2_id");
            var jsonTrip = map.getJsonTrip();
            var jsonDiv = $get('json_id');
            jsonDiv.innerHtml = jsonTrip;
        };
        
        function testWaypoint()
        {
            var map = Sys.Application.findComponent("map2_id");
            var wp = new Object();
            wp.address = 'via Bologna, Prato';
            wp.description = 'via vicino a casa mia';
            wp.gettingInUsers = [];
            wp.gettingOffUsers = [];
            wp.lat = 43.90656;
            wp.lng = 11.11485;
                       
            map._map._editableTrip._routes[2].insertWaypoint(1, wp);
        };
        
        function DetachPassangers()
        {
            var map = Sys.Application.findComponent("map2_id");
            if(map._map._passengerDep != null)
            {
                map._map._passengerDep.detachToTrip();
                map._map._passengerArr.detachToTrip();
            }
        };
        
        function clearEditableTrip(){
            var map = Sys.Application.findComponent("map2_id");
            map.getGMap().clearEditableTrip();
        };
        
        function testGetIstructions()
         {
            var map = Sys.Application.findComponent("map2_id");
            var trip=map._map._editableTrip;
            getIstructions ("outputDiv",trip);
         };
        
        function AttachingPassaenger()
        {
            var mapControl = Sys.Application.findComponent("map2_id");
            var mapObj = mapControl._map;
            var passRadio = document.getElementsByName("pass");
            var routeIndexTB = document.getElementById("passRI");
            var subRouteIndexTB = document.getElementById("passSRI");

            var routeIndex = parseInt(routeIndexTB.value);
            var subRouteIndex = parseInt(subRouteIndexTB.value);
           
            if(subRouteIndex != -1)
            {
                if(passRadio[0].checked)
                    mapObj.gettingInPassenger(routeIndex, subRouteIndex);
                else
                    mapObj.gettingOffPassenger(routeIndex, subRouteIndex);
            }
            else
            {
                var marker = mapObj._editableTrip._markers[routeIndex];
                if(passRadio[0].checked)
                    mapObj.gettingInPassenger(marker);
                else
                    mapObj.gettingOffPassenger(marker);
            }
        };
        
        function _testInit(){
            var map = Sys.Application.findComponent("map2_id"), gmap = map.getGMap();
            var mapDiv = $get('map_id');
            MapControl2.AAAUtils.addDomListener(mapDiv, 'onmouseup', handler);
                
            function handler(e){
                var absPx = MapControl2.AAAUtils.fromEventToAbsPixel(e, gmap);
                var ll = G_NORMAL_MAP.getProjection().fromPixelToLatLng(absPx, gmap.getZoom());
                var label = $get('latlnglabel');
                label.innerHTML = '(' + ll.lat() + ', ' + ll.lng() + ')';
            };
        };
        
        Sys.Application.add_load(_testInit);

        function SwapEditable()
        {
            var mapControl = Sys.Application.findComponent("map2_id");
            if(mapControl._map.isEditable())
                mapControl.transformToUneditableMap();
            else
                mapControl.transformToEditableMap();
        }
        
    </script>
    </body>
</html>
